<template>
  <el-dialog
    width="550px"
    :close-on-click-modal="false"
    :title="title"
    @close="close"
    :visible.sync="visible"
    append-to-body
    class="review"
  >
    <el-form class="information">
      <el-row>
        <el-col :span="6">
          <el-form-item label="单号" label-width="50px" prop="dispatchNumber">
            <el-input v-model="basics.dispatchNumber" class="w100" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="工序" label-width="100px" prop="processName">
            <el-input v-model="basics.processName" class="w75" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="数量" label-width="100px" prop="number">
            <el-input v-model="basics.number" class="w50" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-form class="information" ref="form" :inline="true">
      <el-form-item label="合格" prop="numAuditQualified" label-width="180px" class="mt10">
        <el-input-number
          v-model="formDetail.numAuditQualified"
          :disabled="disable"
          class="w125"
          size="small"
          :min="0"
          :max="basics.number"
        ></el-input-number>
      </el-form-item>

      <el-form-item label="工废" prop="numAuditWasteIndustrial" label-width="180px" class="mt10">
        <el-input-number
          v-model="formDetail.numAuditWasteIndustrial"
          :disabled="disable"
          class="w125"
          size="small"
          :min="0"
          :max="basics.number"
        ></el-input-number>
      </el-form-item>
      <!--
      <el-form-item label="返修" prop="numberRework" label-width="150px">
        <el-input-number
          v-model="formDetail .numberRework"
          :disabled="disable"
          class="w150"
          size="small"
          :min="0"
          :max="5"
        ></el-input-number>
      </el-form-item>
      -->
      <el-form-item label="废料" prop="numAuditWasteMaterial" label-width="180px" class="mt10">
        <el-input-number
          v-model="formDetail.numAuditWasteMaterial"
          :disabled="disable"
          class="w125"
          size="small"
          :min="0"
          :max="basics.number"
        ></el-input-number>
      </el-form-item>
    </el-form>

    <div class="footer">
      <el-button type="primary" @click="save">保存</el-button>
      <el-button @click="close">关闭</el-button>
    </div>
  </el-dialog>
</template>


<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import { State, namespace } from 'vuex-class'

@Component({
  components: {}
})
export default class DialogDetail extends Vue {
  public $refs!: {
    form: any
    addProduct: any
  }
  disable: boolean = false
  title: string = '质检审核'
  visible: boolean = false
  total: string = ''

  formDetail: any = {
    dispatchProcessId: '',
    numAuditQualified: 0,
    numAuditWasteIndustrial: 0,
    //  numberRework: 1,
    numAuditWasteMaterial: 0
  }
  sum() {
    const sum = this.formDetail.numAuditQualified + this.formDetail.numAuditWasteIndustrial + this.formDetail.numAuditWasteMaterial
    this.total = sum
  }
  basics: any = {
    dispatchNumber: '',
    processName: '加工',
    number: 0
  }

  open(dispatchProcessId, number, dispatchNumber, processName) {
    console.log(processName)
    this.formDetail.dispatchProcessId = dispatchProcessId
    this.basics.number = number
    this.basics.dispatchNumber = dispatchNumber
    this.basics.processName = processName
    this.visible = true
  }

  save() {
    this.sum()
    if (this.total <= this.basics.number) {
      if (this.total < this.basics.number) {
        this.$confirm('存在待处理数量，将发起技术评审?', '操作提示', {
          cancelButtonText: '取消',
          confirmButtonText: '确定',
          type: 'warning'
        })
          .then(() => {
            if(this.$checkAuth(['inspectionReviewSubmit'])) {
              this.$emit('review-inspection', { ...this.formDetail })
            } else {
              this.$message({
              type: 'warning',
              message: '您还没有技术评审的权限，请联系管理员！'
            })
            }

            // this.visible = false
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            })
          })
      } else {
        this.$emit('review-inspection', { ...this.formDetail })
        //this.visible = false
      }
    } else {
      this.$alert('您填报的数量超出需审核总数，请重新填写！', '错误提示', {
        confirmButtonText: '确定',
        type: 'error'
      })
    }
  }
  close() {
    this.$refs.form.resetFields()
    this.disable = false
    this.total = ''

    this.formDetail = {
      dispatchProcessId: '',
      numAuditQualified: 0,
      numAuditWasteIndustrial: 0,
      //  numberRework: 1,
      numAuditWasteMaterial: 0
    }
    this.basics = {
      dispatchNumber: '',
      processName: '加工',
      number: 0
    }
    this.visible = false
  }
}
</script>

<style lang="scss" scoped>
.review {
  .footer {
    border-top: 1px solid #eee;
    padding: 10px 20px;
    background: #fefefe;
    text-align: center;
  }
}
</style>
